@extends('Share/home')
<?php
$title='发包单位管理';
$nav_t='系统管理';
$nav_m='发包单位管理';
?>
@section('demand-body')
    <style>
        .Ly-ut-box{
            width:1280px;
            margin:0px auto;
            overflow:hidden;
            background-color:#ffffff;
        }
        .Ly-hd-box{
            width:1280px;
            margin:0 auto;
            background-color: #f6f6f6;
            border-top:2px solid #b2cff0;
            border-bottom:2px solid #b2cff0;
            position:relative;
            overflow:hidden;
        }
        .Ly-hd{
            width:1088px;
            height:40px;
            margin-left:96px;
            margin-top: 20px;
            border-bottom:2px solid #d5d5d5;
            overflow:hidden;
        }
        .Ly-hd-list{
            overflow:hidden;
        }
        .Ly-hd-list li{
            position:absolute;
            top:20px;
            width:70px;
            line-height: 40px;
            font-size:16px;
            font-family:'fzlth';
            color:#383838;
            text-align:center;
            cursor: pointer;
            border-bottom:2px solid #d5d5d5;
        }
        .Ly-hd-list .Ly-hd-list1{
            left:96px;
        }
        .Ly-hd-list .Ly-hd-list2{
            left:226px;
        }
        .Ly-hd-list .Ly-hd-list3{
            left:356px;
        }
        .Ly-hd-list .Ly-hd-list4{
            left:486px;
        }
 
        .Ly-gp-box{
            width:1088px;
            margin-left:96px;
            margin-top:30px;
            overflow: hidden;
        }
        .wh-depot{
 
        }
        .wh-follow{
            position: relative;
        }
        .wh-prompt{
            width:100px;
            height: 32px;
            text-align: center;
            line-height: 32px;
            top: 0;
            left: 200px;
            position: absolute;
            color: red;
        }
        .Ly-hd-list .Ly-lt-add{
            color:#00a7ea;
            border-bottom:2px solid #00a7ea;
        }
        .Ly-gp-le{
            display:none;
            overflow: hidden;
        }
        .Ly-gy-box{
            padding-bottom:14px;
            border-bottom: 1px dashed #d5d5d5;
            overflow: hidden;
        }
        .Ly-gy-ln{
            padding-bottom:16px;
            overflow: hidden;
        }
        .Ly-gy-ln div{
            float:left;
            line-height: 32px;
        }
        .Ly-gy-ln .Ly-gy-lna{
            width:52px;
        }
        .Ly-gy-st select{
            width: 150px;
            padding-left: 10px;
            height: 32px;
            border: #c9c9c9 solid 1px;
            background: -webkit-linear-gradient(#fff, #f1f1f1);
            background: -o-linear-gradient(#fff, #f1f1f1);
            background: -moz-linear-gradient(#fff, #f1f1f1);
            background: linear-gradient(#fff, #f1f1f1);
            filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#f1f1f1');
            cursor: pointer;
            color: #383838;
            font-size: 14px;
        }
        .Ly-ct-box{
            width:1088px;
            margin-top:32px;
            overflow:hidden;
        }
        .Ly-ct-tit,.Ly-ct-cet{
            float:left;
        }
        .Ly-ct-tit{
            width:54px;
            line-height: 40px;
            font-size:14px;
            color:#292929;
        }
        .Ly-ct-cet{
            width:864px;
        }
        .ht-item{
            width: 990px;
            overflow: hidden;
        }
        .ht-list{
            border-radius: 2px;
            float: left;
            padding-bottom: 24px;
            margin-right: 32px;
        }
        .ht-each{
            display: block;
            outline: none;
            border: 0;
            border-radius: 2px;
            background-color: #e5e5e5;
            padding: 0px 20px;
            height: 40px;
            line-height: 40px;
            color: #292929;
            font-size: 16px;
            text-align: center;
            font-family: 'fzlth';
            cursor: pointer;
        }
        .ht-each:hover{
            background: #11b3f4;
            color: #fff;
        }
        .wh-cg{
            background: #00a7ea;
            color: #fff;
        }
 
 
        .Ly-eh-box{
            width:1030px;
            padding-bottom: 32px;
            overflow: hidden;
        }
        .Ly-eh-btn{
            float:left;
            margin-right:32px;
        }
        .Ly-eh-box .Ly_button{
            float:left;
            margin-right:32px;
        }
        .Ly-bn{
            width:96px;
            height: 32px;
            background: #f6f6f6;
        }
        .Ly-bn a{
            width:96px;
            height:32px;
            line-height:32px;
            color: #00a7ea;
        }
        .Ly-bn a:hover{
            color:#027aaa;
        }
        .Ly-dl-box{
            width:1280px;
            margin:0 auto;
            margin-top:34px;
        }
        .category-item{
            width:1220px;
            background:#f6f6f6;
            height: 36px;
            padding-left: 60px;
            border-top:1px solid #dddddd;
            border-bottom:1px solid #dddddd;
            overflow: hidden;
        }
        .category-list{
            float:left;
            line-height: 36px;
            font-family:'fzlth';
            font-size:15px;
            color:#292929;
        }
        .show-item{
            width: 1220px;
            overflow: hidden;
            display: table;
            border-bottom: 1px solid #dddddd;
            padding-left: 60px;
            height: 46px;
        }
        .show-list{
            vertical-align: middle;
            display: table-cell;
            font-family:'宋体';
            font-size:12px;
            color:#666666;
        }
        .w-jt{width:165px;}
        .w-gs{width:140px;}
        .w-bm{width:160px;}
        .w-zu{width:140px;}
        .w-zt{width:135px;}
        .w-ht{width:180px;}
        .w-cz{ width:300px;}
 
        .Ly-ry{
            font-size: 14px;
            color:#00a7ea;
            font-family:'fzlth';
            cursor: pointer;
            margin-top: 7px;
            display: block;
            overflow: hidden;
            width: 10%;
        }
        .condition{
            font-size: 14px;
            font-family:'fzlth';
            text-decoration: none;
        }
        .Ly_button5{
            float: left;
            margin-right: 32px;
            cursor: pointer;
        }
        .wh-bt-add{
            width: 96px;
            height: 32px;
            line-height: 32px;
            text-align: center;
            color: #fff;
            font-weight: bold;
            font-size: 16px;
            border: none;
            background: #00a7ea;
            cursor: pointer;
        }
        .wh-bt-add:hover{
            background:#06b3fa;
        }
        .submit-style{
            display: none;
        }
        .stop{
            font-size: 14px;
            color:grey;
            font-family:'fzlth';
            cursor: pointer;
            margin-top: 7px;
            display: block;
            overflow: hidden;
            width: 10%;
            cursor: auto;
        }
    </style>
    <div class="demand-body">
        <div class="Ly-ut-box" id="anchor">
            <div class="Ly-hd-box">
                <div class="Ly-hd">
                    <ul class="Ly-hd-list">
                        <li class="Ly-hd-list1 Ly-lt-add">添加集团</li>
                        <li class="Ly-hd-list2">添加公司</li>
                        <li class="Ly-hd-list3">添加部门</li>
                        <li class="Ly-hd-list4">添加组</li>
                    </ul>
                </div>
                <div class="Ly-gp-box">
                    <form action="{{URL('system/demander/create')}}" method='post' id="jt"><div class="Ly-gp-le Ly-gp-le1" style="display:block">
                            <input type="hidden" name="_token" value="{{csrf_token()}}">
                            <input type="hidden"  name="PactId" class="wh-depot" />
                            {{--<input type="hidden"  name="ListID" class="wh-modify" />--}}
                            <input type="hidden" name="Type" value="2">
                            <div class="Ly-gy-box">
                                <div class="Ly-gy-ln">
                                    <div class="Ly-gy-lna">集团:</div>
                                    <div class="wh-follow"><input type="text" name="Name" class="Ly_input" maxlength="12" />
                                        <p class="wh-prompt"></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                    <form action="{{URL('system/demander/create')}}" method='post' id="gs">
                        <div class="Ly-gp-le Ly-gp-le2" >
                            <input type="hidden" name="_token" value="{{csrf_token()}}">
                            <input type="hidden" name="PactId" class="wh-depot" />
                            {{--<input type="hidden"  name="ListID" class="wh-modify" />--}}
                            <input type="hidden" name="Type" value="4">
                            <div class="Ly-gy-box">
                                <div class="Ly-gy-ln">
                                    <div class="Ly-gy-lna">集团:</div>
                                    <div class="Ly-gy-st">
                                        <select class="wh-select-group" name="CliqueId">
                                        @foreach($clique as $data)
                                        <option value="{{$data->id}}">{{$data->Name}}</option>
                                        @endforeach
                                        </select>
                                    </div>
                                </div>
                                <div class="Ly-gy-ln">
                                    <div class="Ly-gy-lna">公司:</div>
                                    <div  class="wh-follow"><input type="text" name="Name" class="Ly_input" maxlength="12"/><p class="wh-prompt"></p></div>
                                </div>
                            </div>
                        </div>
                    </form>
                    <form action="{{URL('system/demander/create')}}" method='post' id="bm"><div class="Ly-gp-le Ly-gp-le4" >
                            <input type="hidden" name="_token" value="{{csrf_token()}}">
                            <input type="hidden" name="PactId" class="wh-depot" />
                            {{--<input type="hidden"  name="ListID" class="wh-modify" />--}}
                            <input type="hidden" name="Type" value="6">
                            <div class="Ly-gy-box">
                                <div class="Ly-gy-ln">
                                    <div class="Ly-gy-lna">集团:</div>
                                    <div class="Ly-gy-st">
                                        <select class="wh-select-group each-select" name="CliqueId" sid="2">
                                            @foreach($clique as $data)
                                                <option value="{{$data->id}}">{{$data->Name}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                                <div class="Ly-gy-ln">
                                    <div class="Ly-gy-lna">公司:</div>
                                    <div class="Ly-gy-st">
                                        <select class="wh-select-firm" name="ComId">
                                            @if($clique!=NULL)
                                                @foreach($firstCom as $data)
                                                    <option value="{{$data->id}}">{{$data->Name}}</option>
                                                @endforeach
                                            @else
                                            @endif
                                        </select>
                                    </div>
                                </div>
                                <div class="Ly-gy-ln">
                                    <div class="Ly-gy-lna">部门:</div>
                                    <div class="wh-follow"><input type="text" name="Name" class="Ly_input" maxlength="12" /><p class="wh-prompt"></p></div>
                                </div>
                            </div>
                        </div>
                    </form>
                    <form action="{{URL('system/demander/create')}}" method='post' id="zu">
                        <div class="Ly-gp-le Ly-gp-le3" >
                                <input type="hidden" name="_token" value="{{csrf_token()}}">
                                <input type="hidden" name="PactId" class="wh-depot" />
                            {{--<input type="hidden"  name="ListID" class="wh-modify" />--}}
                                <input type="hidden" name="Type" value="8">
                                <div class="Ly-gy-box">
                                    <div class="Ly-gy-ln">
                                        <div class="Ly-gy-lna">集团:</div>
                                        <div class="Ly-gy-st">
                                            <select class="wh-select-group each-select" name="CliqueId" sid="2">
                                                @foreach($clique as $data)
                                                    <option value="{{$data->id}}">{{$data->Name}}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="Ly-gy-ln">
                                        <div class="Ly-gy-lna">公司:</div>
                                        <div class="Ly-gy-st">
                                            <select class="wh-select-firm each-select" name="ComId" sid="4">
                                                @if($clique!=NULL)
                                                    @foreach($firstCom as $data)
                                                        <option value="{{$data->id}}">{{$data->Name}}</option>
                                                    @endforeach
                                                @else
                                                @endif
                                            </select>
                                        </div>
                                    </div>
                                    <div class="Ly-gy-ln">
                                        <div class="Ly-gy-lna">部门:</div>
                                        <div class="Ly-gy-st">
                                            <select class="wh-select-division" name="DepId">
                                                @if($firstCom!=NULL)
                                                    @foreach(DB::table('business')->select('id','Name')->where('ComId',$firstCom[0]->id)->where('Type',6)->where('Del',1)->get() as $data)
                                                        <option value="{{$data->id}}">{{$data->Name}}</option>
                                                    @endforeach
                                                @else
                                                @endif
                                            </select>
                                        </div>
                                    </div>
                                    <div class="Ly-gy-ln">
                                        <div class="Ly-gy-lna">组:</div>
                                        <div class="wh-follow">
                                            <input type="text" name="Name" class="Ly_input" maxlength="12" />
                                            <p class="wh-prompt"></p>
                                        </div>
                                    </div>
                                </div>
                        </div>
                    </form>
                    <div class="wh-common">
                        <div class="Ly-ct-box">
                            <div class="Ly-ct-tit">合同:</div>
                            <div class="Ly-ct-cet">
                                <ul class="ht-item">
                                    @foreach($pact as $data)
                                    <li class="ht-list">
                                        <div class="ht-each" lid="{{$data->id}}">{{$data->Name}}</div>
                                    </li>
                                    @endforeach
                            </ul>
                            </div>
                        </div>
                        <div class="Ly-eh-box">
                            <div class="Ly-eh-btn">
                                <input type="button" value="添加" class="wh-bt-add" />
                            </div>
                            <div class="Ly-bn Ly_button">
                                <a href="{{URL('system/cContract/index')}}">合同管理</a>
                            </div>
                        </div>
                    </div>
            </div>
        </div>
    </div>
    {{--展示的合同--}}
        <div class="Ly-dl-box">
            <ul class="category-item">
                <li class="category-list w-jt">集团</li>
                <li class="category-list w-gs">公司</li>
                <li class="category-list w-bm">部门</li>
                <li class="category-list w-zu">组</li>
                <li class="category-list w-ht">合同</li>
                <li class="category-list w-zt">状态</li>
                <li class="category-list w-cz">操作</li>
            </ul>
        @foreach($getTree_list as $data)
            <ul class="show-item" id="{{$data->id}}" listType="{{$data->Type}}">
                @if($data->Type==2)
                    <li class="show-list w-jt" id="{{$data->CliqueId}}">{{$data->Name}}</li>
                    <li class="show-list w-gs" id="{{$data->ComId}}"></li>
                    <li class="show-list w-bm" id="{{$data->DepId}}"></li>
                    <li class="show-list w-zu" id=""></li>
                @elseif($data->Type==4)
                    <li class="show-list w-jt" id="{{$data->CliqueId}}"></li>
                    <li class="show-list w-gs" id="">{{$data->Name}}</li>
                    <li class="show-list w-bm" id="{{$data->DepId}}"></li>
                    <li class="show-list w-zu" id=""></li>
                @elseif($data->Type==6)
                    <li class="show-list w-jt" id="{{$data->CliqueId}}"></li>
                    <li class="show-list w-gs" id="{{$data->ComId}}"></li>
                    <li class="show-list w-bm" id="{{$data->DepId}}">{{$data->Name}}</li>
                    <li class="show-list w-zu" id=""></li>
                @elseif($data->Type==8)                 
                    <li class="show-list w-jt" id="{{$data->CliqueId}}"></li>
                    <li class="show-list w-gs" id="{{$data->ComId}}"></li>
                    <li class="show-list w-bm" id="{{$data->DepId}}"></li>
                    <li class="show-list w-zu" id="">{{$data->Name}}</li>
                @endif
                    <li class="show-list w-ht" id="{{$data->PactId}}">
                        @if($data->PactName!=NULL)
                        {{$data->PactName}}
                        @else
                        无
                        @endif
                    </li>
                    <li class="show-list w-zt" id="">
                        @if($data->Del==1)
                            启用
                        @else
                            停用
                        @endif
                    </li>
                    <li class="show-list w-cz" id="">
                        <div class="Ly_button5 Ly_button Ly_button_bg1"><a href="#anchor">修改</a></div>
                        <p class="Ly-ry"><a class="condition" statusList="{{$data->Del}}">
                                @if($data->Del==1)
                                    停用
                                @else
                                    启用
                                @endif
                            </a></p>
                    </li>
                </ul>
            @endforeach
            <form action="{{URL('system/demander/destroy')}}" method="post" class="revise" id="xg">
                <input class="entry-id" name="listId" type="hidden" />
                <input class="destroy-id" name="Del" type="hidden" />
                <input class="submit-style" type="submit" />
            </form>
        </div>
    </div>
 
    <script>
    console.log('{{session('callback')}}')
        window.onload = function(){
            //弹窗
            var _pop = new popup({
                width:'400',
                height:'400',
                content:'<div class="pop-content"><h5>{{session('callback')}}</h5></div><div class="btn-box"><a class="btn-confirm J_companyInfo_start" id="pop_btn_confirm">确定</a></div>',
                hasMask: false,  //是否显示遮罩层
                enter:'spreadIn',
                leave:'spreadOut'
            });
            var _pop1 = new popup({
                width:'400',
                height:'400',
                content:'<div class="pop-content"><h5>启用成功!</h5></div><div class="btn-box"><a class="btn-confirm J_companyInfo_start" id="pop_btn_confirm">确定</a></div>',
                hasMask: true,  //是否显示遮罩层
                enter:'spreadIn',
                leave:'spreadOut'
 
            });
            var _pop2 = new popup({
                width:'400',
                height:'400',
                content:'<div class="pop-content"><h5>启用成功!</h5></div><div class="btn-box"><a class="btn-confirm J_companyInfo_start" id="pop_btn_confirm">确定</a></div>',
                hasMask: true,  //是否显示遮罩层
                enter:'spreadIn',
                leave:'spreadOut'
            });
            $('.btn-confirm').on('click',function(){
                $('.pop-content').slideUp();
            });
 
            //tab切换方法调用
            $(".Ly-hd-list li").click(function(){
                var i = $(".Ly-hd-list li").index(this);
                //具体调用tab切换
                var Ck = new Tab($(this));
                Ck.BV({
                    num : i
                });
                $('.wh-bt-add').val('添加');
                $('.list-id').remove();
                $('.Ly_input').val('');
            });
            //Tab切换的方法
            function Tab(obj){
                this.obj = obj;
                this.settings={
                    num: ''
                }
            }
            Tab.prototype={
                init:function(){
                    var _self = this;
                },
                BV:function(opt){
                    var _self = this;
                    $.extend( _self.settings , opt || {} );
                    _self.Change();
                },
                Change:function(){
                    var _self = this;
                    var i = _self.settings.num;
                    $('.Ly-hd-list li').eq(i).addClass("Ly-lt-add").siblings().removeClass('Ly-lt-add');
                    $('.Ly-gp-le').hide();
                    $('.Ly-gp-le').eq(i).show();
                }
            };
 
            //合同的点击效果及input的赋值
            $('.ht-item').each(function(i,obj){
                $(obj).find('.ht-each').on('click',function(){
                    var i = $(obj).find('.ht-each').index(this);
                    var j = $('.Ly-hd-list li').index($('.Ly-lt-add'));
                    var lid = $(obj).find('.ht-each').eq(i).attr('lid');
                    $('.wh-depot').eq(j).attr('value',lid);
                    if($(obj).find('.ht-each').eq(i).hasClass('wh-cg')){
                        var a=0;
                    }else{
                        var a=1;
                    }
                    $(obj).find('.ht-each').removeClass('wh-cg');
                    if(a==0){
                        $(obj).find('.ht-each').removeAttr('checked');
                        $('.wh-depot').attr('value','');
                    }
                    else if(a==1){
                        $(obj).find('.ht-each').eq(i).addClass('wh-cg');
                    }
                })
            });
            //表单提交及验证
            $('.wh-bt-add').on('click',function(){
                var i = $('.Ly-hd-list li').index($('.Ly-lt-add'));
                var reg=/^[\u4E00-\u9FA5]{1,15}$/;
                var obj = $('.Ly_input').eq(i);
                var val = $.trim(obj.val());
                var fid = $('.Ly-gp-box form').eq(i).attr('id');
                //验证
                if(val==''){
                    $('.wh-prompt').eq(i).text('请输入添加内容');
                }else{
                    if (val.match(reg)){
                        $('.wh-prompt').eq(i).text("保存成功！");
                        $('#'+fid).submit();
                    }else{
                        $('.wh-prompt').eq(i).text("必须全部为汉字!");
                    }
                }
            });
            //弹窗调用
            if('{{session('callback')}}'!==''){
                _pop.create();
            }
            //回车键
            $(".Ly_input").keydown(function() {
                if (event.keyCode == "13") {//keyCode=13是回车键
                    $('.wh-bt-add').click();
                }
            });
 
            //下拉改变联动调用
            $('.each-select').on('change',function(){
                var transfer = new getlist();
                //传入参数
                transfer.Part({
                    type : $(this).attr('sid'),
                    jid : $(this).val()
                });
            });
            //ajax联动的方法
            function getlist(){
                this.settings={
                    type : '',//集团返回or公司返回
                    jid : ''//集团参数
                };
            }
            getlist.prototype={
                init:function(){
                    var _self = this;
                },
                Part:function(opt){
                    var _self = this
                    $.extend( _self.settings , opt || {} );
                    _self.execute();
                },
                execute: function () {
                    var _self = this;
                    $.ajax({
                        url: 'ajax_select',
                        type: 'post',
                        data: {Type: _self.settings.type,pid: _self.settings.jid,_token:'{{csrf_token()}}'},
                        success:function(data){
                            var item = JSON.parse(data);
                            var list = item.data;
                            var num = $('.Ly-hd-list li').index($('.Ly-lt-add'));
                            if(_self.settings.type==2){
                                $('.wh-select-firm').eq(num-2).empty();
                                if(num==3){
                                    $('.wh-select-division').empty();
                                }
                                for (var i = 0; i <list.length; i++) {
                                    var str = '<option value="'+list[i].id+'">'+list[i].Name+'</option>';
                                    $('.wh-select-firm').eq(num-2).append(str);
                                }
                            }
                            else if(_self.settings.type==4){
                                $('.wh-select-division').empty();
                                for (var i = 0; i <list.length; i++) {
                                    var str = '<option value="'+list[i].id+'">'+list[i].Name+'</option>';
                                    $('.wh-select-division').append(str);
                                }
                            }
                        }
                    });
                }
            };
 
            //修改
            $('.Ly-dl-box').on('click','.Ly_button5',function(){
                var Par = $(this).parents();
                var _obj = Par[1];
                var entryID = $(_obj).attr('id');
                $('.wh-bt-add').val('修改');
                //合同id
                var cont = $(_obj).find('.w-ht').attr('id');
                $('.ht-each').removeClass('wh-cg');
                $('.ht-each').each(function(i,e){
                    var _each = $(e).attr('lid');
                    if(_each==cont){
                        $('.ht-each').eq(i).addClass("wh-cg");
                    }
                });
                //合同id
                var _jht = $(_obj).find('.w-ht').attr('id');
                //集团
                var _jt = $(_obj).find('.w-jt').text();
                ///公司
                var _gs = $(_obj).find('.w-gs').text();
                //部门
                var _bm = $(_obj).find('.w-bm').text();
                //组
                var _zu = $(_obj).find('.w-zu').text();
                //teb切换方法定义
                var Ck = new Tab($(_obj));
                //修改方法定义
                var modify = new revise();
                //定义listid的input
                var aa = '<input name="listId" class="list-id" type="hidden" />';
                if(_zu !== ""){
                    Ck.BV({
                        num : 3
                    });
                    modify.parameter({
                        entryId : entryID,
                        type : 8
                    });
                    $('.Ly-gp-le').eq(3).find('.Ly_input').val(_zu);
                    $('.wh-depot').eq(3).val(_jht);
                    $('.list-id').remove();
                    $('.Ly-gp-le').eq(3).append(aa);
                    $('.list-id').val(entryID);
                }
                else{
                    if(_bm !== ""){
                        Ck.BV({
                            num : 2
                        });
                        modify.parameter({
                            entryId : entryID,
                            type : 6
                        });
                        $('.Ly-gp-le').eq(2).find('.Ly_input').val(_bm);
                        $('.wh-depot').eq(2).val(_jht);
                        $('.list-id').remove();
                        $('.Ly-gp-le').eq(2).append(aa);
                        $('.list-id').val(entryID);
                    }
                    else{
                        if(_gs !== ""){
                            Ck.BV({
                                num : 1
                            });
                            modify.parameter({
                                entryId : entryID,
                                type : 4
                            });
                            $('.Ly-gp-le').eq(1).find('.Ly_input').val(_gs);
                            $('.wh-depot').eq(1).val(_jht);
                            $('.list-id').remove();
                            $('.Ly-gp-le').eq(1).append(aa);
                            $('.list-id').val(entryID);
                        }
                        else if(_jt !== ""){
                            Ck.BV({
                                num : 0
                            });
                            $('.Ly-gp-le').eq(0).find('.Ly_input').val(_jt);
                            $('.wh-depot').eq(0).val(_jht);
                            $('.list-id').remove();
                            $('.Ly-gp-le').eq(0).append(aa);
                            $('.list-id').val(entryID);
                        }
                    }
                }
            });
            //修改ajax
            function revise(){
                this.settings = {
                    entryId : '',
                    type : ''
                }
            };
            revise.prototype = {
                init:function(){
                    var _self = this;
                },
                parameter:function(opt){
                    var _self = this;
                    $.extend( _self.settings , opt || {} );
                    _self.interface();
                },
                interface:function(){
                    var _self = this;
                    $.ajax({
                        url:'edit',
                        type:'post',
                        data:{Type:_self.settings.type,listId:_self.settings.entryId,_token:'{{csrf_token()}}'},
                        success:function(data){
                            var item = JSON.parse(data);
                            //console.log(item);
                            var _data = item.data;
                            var _clique = item.clique;
                            var _Com = item.Com||null;
                            var _Dep = item.Dep||null;
                            //console.log(_data,_clique,_Com,_Dep);
                            var type = _self.settings.type;
                            if(type==2){
                            }
                            else if(type==4){
                                _self.first.call(_self,0,_clique,_data);
                            }
                            else if(type==6){
                                _self.first.call(_self,1,_clique,_data);
                                _self.second.call(_self,0,_Com,_data);
                            }
                            else if(type==8){
                                _self.first.call(_self,2,_clique,_data);
                                _self.second.call(_self,1,_Com,_data);
                                _self.third.call(_self,0,_Dep,_data);
                            }
                        }
                    })
                },
                first:function(e,arr,now){
                    var _self = this;
                    $('.wh-select-group').eq(e).empty();
                    for (var i = 0; i <arr.length; i++) {
                        //console.log(arr[i]);
                        var str = '<option value="'+arr[i].id+'"';
                        if(now[0]['CliqueId']==arr[i].id){
                            str+='selected="selected"';
                        }
                        str +='>'+arr[i].Name+'</option>';
                        $('.wh-select-group').eq(e).append(str);
                    }
                },
                second:function(e,arr,now){
                    var _self = this;
                    $('.wh-select-firm').eq(e).empty();
                    for (var i = 0; i <arr.length; i++) {
                        var str = '<option value="'+arr[i].id+'"';
                        if(now[0]['ComId']==arr[i].id){
                            str+='selected="selected"';
                        }
                        str +='>'+arr[i].Name+'</option>';
                        $('.wh-select-firm').eq(e).append(str);
                    }
                },
                third:function(e,arr,now){
                    var _self = this;
                    $('.wh-select-division').eq(e).empty();
                    for (var i = 0; i <arr.length; i++) {
                        var str = '<option value="'+arr[i].id+'"';
                        if(now[0]['DepId']==arr[i].id){
                            str+='selected="selected"';
                        }
                        str +='>'+arr[i].Name+'</option>';
                        $('.wh-select-division').eq(e).append(str);
                    }
                }
            };
 
            //停用
            $('.Ly-dl-box').on('click','.Ly-ry',function(){
                var Child = $(this).children();
                var _cd = Child[0];
                var _val = $(_cd).text();
                var state = $(_cd).attr('statusList');
                var Par = $(this).parents();
                var _pa = Par[1];
                var entry = $(_pa).attr('id');
                var type = $(_pa).attr('listType');
                var id = $(_pa).attr('id');
                var COS = new destroy(this);
                COS.parameter({
                    state: state,
                    entry: entry,
                    type: type,
                    id: id,
                    term : _val
                })
            });
            //停用ajax方法
            function destroy(obj){
                this.obj = obj;
                this.settings = {
                    state : '',
                    entry : '',
                    type : '',
                    id : '',
                    term : ''
                }
            }
            destroy.prototype = {
                init:function(){
                    var _self = this;
                },
                parameter:function(opt){
                    var _self = this;
                    $.extend( _self.settings , opt || {} );
                    _self.execute();
                },
                execute:function(){
                    var _self = this;
                    var _child = $(_self.obj).children();
                    var _bt = $(_child)[0];
                    var _superior = $(_self.obj).parents();
                    var _current = $(_superior)[1];
                    $.ajax({
                        url: 'destroy',
                        type: 'post',
                        data: {listId:_self.settings.entry,Del:_self.settings.state,Type:_self.settings.type,_token:'{{csrf_token()}}'},
                        success: function(data){
                            console.log(data)
                            var state = _self.settings.state;
                            if(state==1){
                                $(_self.obj).find('.condition').attr('statusList','0');
                                $(_current).find('.w-zt').text('停用');
                                $(_bt).text('启用');
                                _self.nest();
                                _pop2.create();
                            }
                            else if(state==0){
                                $(_self.obj).find('.condition').attr('statusList','1');
                                $(_current).find('.w-zt').text('启用');
                                $(_bt).text('停用');
                                _self.invoke();
                                _pop1.create();
                            }
                        }
                    });
                },
                attach:function(o){
                    var _self = this;
                    var id =_self.settings.id;
                    $('.show-item').each(function(i,e) {
                        var nd=$(e);
                        var attrid=nd.find(o).attr("id");
                        if(attrid==id){
                            nd.find('.w-zt').text('停用');
                            nd.find('.condition').text('启用');
                            nd.find('.condition').attr('statuslist','0');
                            nd.find(".Ly-ry").removeClass("Ly-ry").addClass("stop");
                        }
                    });
                },
                recover:function(o){
                    var _self = this;
                    var id =_self.settings.id;
                    $('.show-item').each(function(i,e) {
                        var nd=$(e);
                        var attrid=nd.find(o).attr("id");
                        if(attrid==id){
                            nd.find(".stop").removeClass("stop").addClass("Ly-ry");
                        }
                    });
                },
                nest:function(){
                    var _self = this;
                    var type = _self.settings.type;
                    if(type==2){
                        _self.attach.call(_self,'.w-jt');
                    }
                    else if(type==4){
                        _self.attach.call(_self,'.w-gs');
                    }
                    else if(type==6){
                        _self.attach.call(_self,'.w-bm');
                    }
                },
                invoke:function(){
                    var _self = this;
                    var type = _self.settings.type;
                    if(type==2){
                        _self.recover.call(_self,'.w-jt');
                    }
                    else if(type==4){
                        _self.recover.call(_self,'.w-gs');
                    }
                    else if(type==6){
                        _self.recover.call(_self,'.w-bm');
                    }
                }
            };
 
            //初始停用状态改变
            var Lylist=$('.show-item');
            for(var i=0;i<Lylist.length;i++){
                var nd=Lylist.eq(i);
                var type=parseInt(nd.attr("listtype"));
                var state = nd.find(".condition").attr('statuslist');
                if(state=="0"){
                    for(var j=i+1;parseInt(Lylist.eq(j).attr("listtype"))>type;j++){
                        Lylist.eq(j).find(".Ly-ry").removeClass("Ly-ry").addClass("stop");
                    }
                    i=j-1;
                }
            }
        };
    </script>
@endsection